package top.xqf.homework.service.impl;

import org.springframework.stereotype.Service;
import top.xqf.homework.base.BaseResult;
import top.xqf.homework.dao.TbYsAtrDAO;
import top.xqf.homework.entity.TbYsAtr;
import top.xqf.homework.service.AtrService;

import java.util.List;

@Service
public class AtrServiceImpl implements AtrService {


    private final TbYsAtrDAO tbYsAtrDAO;

    public AtrServiceImpl(TbYsAtrDAO tbYsAtrDAO) {
        this.tbYsAtrDAO = tbYsAtrDAO;
    }

    @Override
    public BaseResult<List<TbYsAtr>> query(TbYsAtr tbYsAtr) throws Exception{
        BaseResult<List<TbYsAtr>> result=new BaseResult<>();
        result.setCode(200);
        result.setSuccess(true);
        result.setMessage("");
        result.setData(tbYsAtrDAO.query(tbYsAtr));
        return result;
    }


    @Override
    public BaseResult<TbYsAtr> add(TbYsAtr tbYsAtr) throws Exception{
        BaseResult<TbYsAtr> result=new BaseResult<>();
        int n=tbYsAtrDAO.add(tbYsAtr);
        result.setCode(n==1?200:500);
        result.setSuccess(n==1);
        result.setMessage(n==1?"添加成功":"添加失败");
        result.setData(tbYsAtr);
        return result;
    }

    @Override
    public BaseResult<TbYsAtr> update(TbYsAtr tbYsAtr) throws Exception{
        BaseResult<TbYsAtr> result=new BaseResult<>();
        int n=tbYsAtrDAO.update(tbYsAtr);
        result.setCode(n==1?200:500);
        result.setSuccess(n==1);
        result.setMessage(n==1?"修改成功":"修改失败");
        result.setData(tbYsAtr);
        return result;
    }


    @Override
    public BaseResult<TbYsAtr> delete(TbYsAtr tbYsAtr) throws Exception{
        BaseResult<TbYsAtr> result=new BaseResult<>();
        int n=tbYsAtrDAO.delete(tbYsAtr);
        result.setCode(n==1?200:500);
        result.setSuccess(n==1);
        result.setMessage(n==1?"删除成功":"删除失败");
        result.setData(tbYsAtr);
        return result;
    }
}
